package com.cn.hotel.dao.Impl;

import com.cn.hotel.dao.IRoomTypeDao;
import com.cn.hotel.model.RoomTypeModel;
import com.cn.hotel.model.ServiceItemsModel;
import com.cn.hotel.util.GetSqlSession;
import com.cn.hotel.util.JDBC;
import com.mysql.cj.protocol.ResultsetRow;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoomtypeImpl implements IRoomTypeDao {
    @Override
    public List<RoomTypeModel> findAll(RoomTypeModel roomTypeModel) {
        return GetSqlSession.getSqlSession().selectList("com.cn.hotel.dao.IRoomTypeDao.findAll",roomTypeModel);

    }

    @Override
    public int getNumber(RoomTypeModel roomTypeModel) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.hotel.dao.IRoomTypeDao.getNumber",roomTypeModel);
    }

    /**
     * 增加
     *
     * @param roomTypeModel
     * @return
     */
    @Override
    public int add(RoomTypeModel roomTypeModel) {
        return GetSqlSession.getSqlSession().insert("com.cn.hotel.dao.IRoomTypeDao.add",roomTypeModel);
    }

    /**
     * 通过id查询信息
     *
     * @param temp
     * @return
     */
    @Override
    public RoomTypeModel finById(Integer temp) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.hotel.dao.IRoomTypeDao.finById",temp);
    }

    /**
     * 保存编辑
     *
     * @param roomTypeModel
     * @return
     */
    @Override
    public int edit(RoomTypeModel roomTypeModel) {
        return GetSqlSession.getSqlSession().update("com.cn.hotel.dao.IRoomTypeDao.edit",roomTypeModel);
    }

    @Override
    public int delete(Integer aa) {
        return GetSqlSession.getSqlSession().delete("com.cn.hotel.dao.IRoomTypeDao.delete",aa);
    }
//------------------下面是前端页面调取数据逻辑代码------------------------

    /**
     * 网站首页调取
     * @return
     */
    @Override
    public List<RoomTypeModel> getRoomTypeModelList() {
        StringBuilder sql = new StringBuilder("select * from roomtype");
        ResultSet resultSet = JDBC.getResultSet(sql.toString());
        List<RoomTypeModel> list = new ArrayList<>();
        try {
            while (resultSet.next()) {
                RoomTypeModel model = new RoomTypeModel();
                model.setName(resultSet.getString("name"));
                model.setHref(resultSet.getString("href"));
                list.add(model);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}
